package com.example.demo.untils;

import java.sql.*;
import java.util.Properties;


public class JDBCTools {
	public static void release(ResultSet rs, Statement statement, Connection con) throws SQLException {
		/**
		 * 释放ResultSet Statement Connection三个连接的方法
		 */
		try {
			if (rs != null)
				rs.close();
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		try {
			if (statement != null)
				statement.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (con != null)
				con.close();
		}
	}

	public static void release(Statement statement, Connection con) throws SQLException {
		/**
		 * Statement Connection两个连接的方法
		 */
		try {
			if (statement != null)
				statement.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (con != null)
				con.close();
		}
	}

	public static Connection getConnection(String driverClass, String jdbcUrl, String user, String password) throws Exception {
		/*
		 * 创建数据库的连接
		 */
		driverClass = "com.mysql.jdbc.Driver";
		jdbcUrl = "jdbc:mysql://rm-wz96xq692epaynj6bo.mysql.rds.aliyuncs.com:3306/wtrj_zs";
		user = "wtrj_zs";
		password = "Wtrj1688";

		Driver driver = (Driver) Class.forName(driverClass).newInstance();

		Properties info = new Properties();
		info.put("user", user);
		info.put("password", password);
		Connection connection = driver.connect(jdbcUrl, info);
		return connection;
	}
}
